package com.wendy.utils;

import com.wendy.web.response.ResponseWrapper;

/**
 * @author zhuwending
 */
public class ResponseUtil {
    public static final String DUPLICATE_ERROR_MSG = "### Error updating database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry";

    public static ResponseWrapper errorResponse(String msg) {
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setMsg(msg);
        responseWrapper.setSuccess(false);
        responseWrapper.setStatus(1);
        return responseWrapper;
    }

    public static ResponseWrapper errorResponse(String msg, int status) {
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setMsg(msg);
        responseWrapper.setStatus(status);
        responseWrapper.setSuccess(false);
        return responseWrapper;
    }

    public static ResponseWrapper errorResponse(String msg, int status, String key, Object object) {
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setMsg(msg);
        responseWrapper.setStatus(status);
        responseWrapper.setSuccess(false);
        responseWrapper.addAttribute(key, object);
        return responseWrapper;
    }

    public static ResponseWrapper errorResponse(String key, Object object, String msg) {
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setMsg(msg);
        responseWrapper.setSuccess(false);
        responseWrapper.setStatus(1);
        responseWrapper.addAttribute(key, object);
        return responseWrapper;
    }

    public static ResponseWrapper errorResponse(String msg, String url) {
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setMsg(msg);
        responseWrapper.setSuccess(false);
        responseWrapper.setStatus(1);
        responseWrapper.setSourceUrl(url);
        return responseWrapper;
    }

    public static ResponseWrapper successResponse(String msg) {
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setMsg(msg);
        responseWrapper.setSuccess(true);
        responseWrapper.setStatus(0);
        return responseWrapper;
    }

    public static ResponseWrapper successResponse(String msg, int status) {
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setMsg(msg);
        responseWrapper.setStatus(status);
        responseWrapper.setSuccess(true);
        return responseWrapper;
    }

    public static ResponseWrapper successResponse(String msg, int status, String key, Object object) {
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setMsg(msg);
        responseWrapper.setStatus(status);
        responseWrapper.setSuccess(true);
        responseWrapper.addAttribute(key, object);
        return responseWrapper;
    }

    public static ResponseWrapper successResponse(String key, Object object, String msg) {
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setMsg(msg);
        responseWrapper.setSuccess(true);
        responseWrapper.setStatus(0);
        responseWrapper.addAttribute(key, object);
        return responseWrapper;
    }

    public static ResponseWrapper successResponse(String key, Object object) {
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setMsg("successfully");
        responseWrapper.setSuccess(true);
        responseWrapper.setStatus(0);
        responseWrapper.addAttribute(key, object);
        return responseWrapper;
    }

    public static ResponseWrapper successResponse(String msg, String url) {
        ResponseWrapper responseWrapper = new ResponseWrapper();
        responseWrapper.setMsg(msg);
        responseWrapper.setSuccess(true);
        responseWrapper.setStatus(0);
        responseWrapper.setSourceUrl(url);
        return responseWrapper;
    }
}
